
var target = UIATarget.localTarget();
var loop = 1; // true sets infinite loop count
var loopCounter = 0; 

while(loopCounter < loop)
{
//general 
	
loopCounter++;
UIALogger.logMessage("SCRIPT RUN : " + loopCounter);

//MultiTask Check
//UIALogger.logStart("++++++++++++++++++++ Multitask Testing ++++++++++++++++++++");
//UIALogger.logMessage("Starting multitask testing..");
//target.deactivateAppForDuration(2);
//UIALogger.logPass("Multitasking confirmed");
// Alert detected. Expressions for handling alerts should be moved into the UIATarget.onAlert function definition.
try{
		
target.frontMostApp().alert().defaultButton().tap();
	}
	catch(e)
	{
		UIALogger.logMessage("No alert to remove");
	}
	
UIATarget.localTarget().delay(1);	
UIALogger.logStart("+++++++++++++++++ Starting navigation test in portrait mode +++++++++++++++++"); 
try{
target.frontMostApp().mainWindow().images()[1].toolbar().tapWithOptions({tapOffset:{x:0.30, y:0.68}});
}
catch(e)
{
target.frontMostApp().mainWindow().images()[2].toolbar().tapWithOptions({tapOffset:{x:0.30, y:0.68}});	
}
UIATarget.localTarget().delay(1);
try{
target.frontMostApp().mainWindow().images()[1].toolbar().buttons()["ipad genre movies normal"].tap();
}
catch(e)
{
target.frontMostApp().mainWindow().images()[2].toolbar().buttons()["ipad genre movies normal"].tap();
}
UIATarget.localTarget().delay(1);
target.logElementTree();
try{
target.frontMostApp().mainWindow().images()[1].toolbar().buttons()["ipad genre news normal"].tap();
}
catch(e)
{
target.frontMostApp().mainWindow().images()[2].toolbar().buttons()["ipad genre news normal"].tap();
}
UIATarget.localTarget().delay(1);
try{
	target.frontMostApp().mainWindow().images()[1].toolbar().buttons()["ipad genre movies normal"].tap();
}
catch(e)
{

target.frontMostApp().mainWindow().images()[2].toolbar().buttons()["ipad genre sports normal"].tap();
}
	UIATarget.localTarget().delay(1);
try{	
target.frontMostApp().mainWindow().images()[1].toolbar().buttons()["ipad genre allchannels normal"].tap();
}
catch(e)
{
target.frontMostApp().mainWindow().images()[2].toolbar().buttons()["ipad genre allchannels normal"].tap();
}
	UIATarget.localTarget().delay(1);
UIALogger.logPass("Completed navigation tests");
UIATarget.localTarget().delay(1);
target.frontMostApp().mainWindow().toolbar().buttons()[1].tap();
target.frontMostApp().mainWindow().popover().navigationBar().buttons()["btn blue done"].tap();
target.frontMostApp().mainWindow().toolbar().buttons()[2].tap();
target.frontMostApp().mainWindow().popover().navigationBar().buttons()["btn blue done"].tap();
	
	
target.setDeviceOrientation(UIA_DEVICE_ORIENTATION_LANDSCAPERIGHT);	
UIATarget.localTarget().delay(1);
UIALogger.logStart("+++++++++++++++++ Starting navigation test in landscape mode +++++++++++++++++"); 
target.frontMostApp().mainWindow().images()[2].toolbar().buttons()["ipad genre sports normal"].tap();
target.frontMostApp().mainWindow().images()[2].toolbar().buttons()["ipad genre movies normal"].tap();
target.frontMostApp().mainWindow().images()[2].toolbar().buttons()["ipad genre news normal"].tap();
target.frontMostApp().mainWindow().images()[2].toolbar().buttons()["ipad genre movies normal"].tap();
target.frontMostApp().mainWindow().images()[2].toolbar().buttons()["ipad genre sports normal"].tap();

UIALogger.logPass("Completed navigation tests");
target.frontMostApp().mainWindow().toolbar().buttons()[1].tap();
target.frontMostApp().mainWindow().popover().navigationBar().buttons()["btn blue done"].tap();
target.frontMostApp().mainWindow().toolbar().buttons()[2].tap();
target.frontMostApp().mainWindow().popover().navigationBar().buttons()["btn blue done"].tap();

			target.setDeviceOrientation(UIA_DEVICE_ORIENTATION_PORTRAIT);	
			
		UIATarget.localTarget().delay(2);
target.frontMostApp().mainWindow().images()[2].toolbar().buttons()["ipad genre allchannels normal"].tap();
	
	++loopCounter;
}

